# -*- coding: utf-8 -*-
# @File     : position_to_lat_lon.py
# @Author   : bingjia
# @Time     : 2020/9/22 18:40
# @Desc     : 将位置信息转为经纬度信息

import json
import requests
from urllib.request import quote


def get_lng_lat(address):
    """
    获取经纬度信息
    :param address:
    :return:
    """
    ak = '5ieMMexWmzB9jivTq6oCRX9j&callback'
    url = 'http://api.map.baidu.com/geocoding/v3/'
    uri = url + '?' + 'address=' + quote(address) + '&output=json' + '&ak=' + ak + '&callback=showLocation%20' + '//GET%E8%AF%B7%E6%B1%82'
    res = requests.get(uri).text
    lat, lng = json.loads(res)['result']['location']['lat'], json.loads(res)['result']['location']['lng']

    return lat, lng
